//
//  HomePageViewController.m
//  AnimationRecommend
//
//  Created by ljm on 2017/2/14.
//  Copyright © 2017年 ljm. All rights reserved.
//

#import "HomePageViewController.h"

#import "HomeMainController.h"

#import "TodayVC.h"
#import "LastOneDayVC.h"
#import "LastTwoDayVC.h"
#import "LastThreeDayVC.h"
#import "LastFourDayVC.h"
#import "LastFiveDayVC.h"


@interface HomePageViewController ()

@property(nonatomic,strong) NSArray *menuList;

@end

@implementation HomePageViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden = YES;

}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    //自动滑到第几页
//    [self.magicView switchToPage:0 animated:YES];
    [UIApplication sharedApplication].statusBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    self.navigationController.navigationBarHidden = NO;
    [UIApplication sharedApplication].statusBarHidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];

//        self.magicView.bounces = YES;
//        self.magicView.headerHidden = NO;
//        self.magicView.itemSpacing = 20.f;
        self.magicView.switchEnabled = YES;
        self.magicView.separatorHidden = NO;
    self.magicView.itemScale = 1.5;//被选中的文本的放大倍数
//    self.magicView.headerHeight = 40;
//    self.magicView.navigationHeight = 40;
//    self.magicView.againstStatusBar = YES;
    //    self.magicView.sliderExtension = 5.0;
    //    self.magicView.switchStyle = VTSwitchStyleStiff;
    //    self.magicView.navigationInset = UIEdgeInsetsMake(0, 50, 0, 0);
//        self.magicView.headerView.backgroundColor = RGBCOLOR(243, 40, 47);
    self.magicView.navigationColor = [UIColor whiteColor];
    self.magicView.layoutStyle = VTLayoutStyleDefault;
//        self.view.backgroundColor = RGBCOLOR(243, 40, 47);
    
    
    [self generateHeadData];
    [self.magicView reloadData];
}


#pragma mark -- 状态栏改变事件
- (void)statusBarOrientationChanges:(NSNotification *)notification {
//    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:YES];
    [UIApplication sharedApplication].statusBarHidden = YES;
//    [UIViewController prefersStatusBarHidden]
}


#pragma mark -- VTmagicViewDatasource
- (NSArray<NSString *> *)menuTitlesForMagicView:(VTMagicView *)magicView {
    return _menuList;
}

#pragma mark -- 导航条内的文字设置
- (UIButton *)magicView:(VTMagicView *)magicView menuItemAtIndex:(NSUInteger)itemIndex {
    static NSString *identifier = @"itemIdentifier";
    UIButton *menuItem = [magicView dequeueReusableItemWithIdentifier:identifier];
    
    if (!menuItem) {
        menuItem = [UIButton buttonWithType:UIButtonTypeCustom];
        [menuItem setTitleColor:RGBCOLOR(50, 50, 50) forState:UIControlStateNormal];
        [menuItem setTitleColor:RGBCOLOR(65, 98, 124) forState:UIControlStateSelected];
        menuItem.titleLabel.font = AAFont(25);
    }
    NSString *title = _menuList[itemIndex];
    [menuItem setTitle:title forState:UIControlStateNormal];
    
    return menuItem;
}


#pragma mark -- 区别不同时间内的视图
- (UIViewController *)magicView:(VTMagicView *)magicView viewControllerAtPage:(NSUInteger)pageIndex {
    
    static NSString *TodayCell = @"TodayCell.identifier";
    static NSString *LastDayCell = @"LastDayCell.identifier";
    static NSString *LastTwoDayCell = @"LastTwoDayCell.identifier";
    static NSString *LastThreeDayCell = @"LastThreeDayCell.identifier";
    static NSString *LastFourDayCell = @"LastFourDayCell.identifier";
    static NSString *LastFiveDayCell = @"LastFiveDayCell.identifier";
    static NSString *mainId = @"mainCell.identifier";
    
    switch (pageIndex) {
        case 0:
        {
                                TodayVC *tvc = [magicView dequeueReusablePageWithIdentifier:TodayCell];
                                if (!tvc) {
                                    tvc = [[TodayVC alloc]init];
                                }
                                return tvc;
        }
            break;
            
        case 1:
        {
                                LastOneDayVC *LastOneVC = [magicView dequeueReusablePageWithIdentifier:LastDayCell];
                                if (!LastOneVC) {
                                    LastOneVC = [[LastOneDayVC alloc] init];
                                }
                                return LastOneVC;
        }
            break;
            
        case 2:
        {
                                LastTwoDayVC *LastTwoVC = [magicView dequeueReusablePageWithIdentifier:LastTwoDayCell];
                                if (!LastTwoVC) {
                                    LastTwoVC = [[LastTwoDayVC alloc] init];
                                }
                                return LastTwoVC;
        }
            break;
        
        case 3:
        {
                                LastThreeDayVC *LastThreeVC = [magicView dequeueReusablePageWithIdentifier:LastThreeDayCell];
                                if (!LastThreeVC) {
                                    LastThreeVC = [[LastThreeDayVC alloc] init];
                                }
                                return LastThreeVC;
        }
            break;
        
        case 4:
        {
                                LastFourDayVC *LastFourVC = [magicView dequeueReusablePageWithIdentifier:LastFourDayCell];
                                if (!LastFourVC) {
                                    LastFourVC = [[LastFourDayVC alloc] init];
                                }
                                return LastFourVC;
        }
            break;
            
        case 5:
        {
                            LastFiveDayVC *LastFiveVC = [magicView dequeueReusablePageWithIdentifier:LastFiveDayCell];
                            if (!LastFiveVC) {
                                LastFiveVC = [[LastFiveDayVC alloc] init];
                            }
                            return LastFiveVC;
        }
            break;
            
        default:
        {
                            HomeMainController *mainVC = [magicView dequeueReusablePageWithIdentifier:mainId];
                            if (!mainVC) {
                                mainVC = [[HomeMainController alloc]init];
                            }
                            return mainVC;
        }
            break;
    }
    
}

#pragma mark -- VTMagicDelegate
#pragma mark -- 点击选中了第几页
- (void)magicView:(VTMagicView *)magicView didSelectItemAtIndex:(NSUInteger)itemIndex {
    NSLog(@"点击选中了第%lu页",(unsigned long)itemIndex);

}

#pragma mark -- 滑动选中了第几页
- (void)magicView:(VTMagicView *)magicView viewDidAppear:(__kindof UIViewController *)viewController atPage:(NSUInteger)pageIndex {
    NSLog(@"滑动选中了第%lu页",(unsigned long)pageIndex);
}

#pragma mark -- 生成头部移动标题
- (void)generateHeadData {
    NSMutableArray *menuArray = [NSMutableArray arrayWithCapacity:6];
    NSArray *dataArray = @[@"今天",@"昨天",@"前天",@"三天前",@"四天前",@"五天前"];
    for (NSInteger index = 0; index < 6; index ++) {
        [menuArray addObject:[NSString stringWithFormat:@"%@",dataArray[index]]];
    }
    [menuArray addObject:@"往期推荐"];
    
    _menuList = menuArray;
}

#pragma mark -- 组合头部的导航标题 小+号
- (void)integrateComponents {
    UIButton *rightBtn = [[UIButton alloc]initWithFrame:AAdaptionRect(0, 0, 50, 30)];
//    [rightBtn addTarget:self action:@selector(subscribeAction) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn setTitleColor:RGBCOLOR(169, 37, 37) forState:UIControlStateNormal];
    [rightBtn setTitleColor:RGBACOLOR(169, 37, 37, 0.5) forState:UIControlStateSelected];
    
    [rightBtn setTitle:@"+" forState:UIControlStateNormal];
    
    rightBtn.titleLabel.font = [UIFont boldSystemFontOfSize:28];
    rightBtn.center = self.view.center;
    
    self.magicView.rightNavigatoinItem = rightBtn;
}


//#pragma mark -- action事件
//- (void)subscribeAction {
//    NSLog(@"subscribeAction");
//    
//    [self.magicView setHeaderHidden:!self.magicView.isHeaderHidden duration:0.35];
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
